package com.audaque.springboot.foshanupload.web.raspcloud.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import com.audaque.springboot.foshanupload.web.raspcloud.entity.*;
import com.audaque.springboot.foshanupload.web.raspcloud.req.*;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;

import org.springframework.http.HttpStatus;
import com.audaque.springboot.foshanupload.web.raspcloud.service.IRoleService;
import com.audaque.springboot.foshanupload.web.raspcloud.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;



import io.swagger.v3.oas.annotations.media.Schema;




import lombok.*;


/**
 * <p>
 * 后台用户角色表 前端控制器
 * </p>
 *
 * @author chinaben
 * @since 2025-07-02
 */
@RestController

@Api(value = "后台用户角色表 前端控制器")

@RequestMapping("/role")
public class RoleController {


    @Autowired
    private IRoleService iRoleService;

    @PostMapping(value = "/page")
    @ApiOperation(value = "后台用户角色表 分页查询")
    public Page<Role> page(@RequestBody RoleReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        Page<Role> page = iRoleService.page(new Page<>(req.getPage(), req.getRows()),queryWrapper);
        return page;
    }




    @PostMapping(value = "/list")
    @ApiOperation(value = "后台用户角色表 列表查询")
    public List<Role> list(@RequestBody RoleReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        List<Role> list = iRoleService.list(queryWrapper);
        return list;
    }





    @GetMapping(value = "/{id}")
     @ApiOperation(value = "后台用户角色表 单体查询")
    public Role getById(@PathVariable("id") String id) {
        Role one=iRoleService.getById(id);
        return one;
    }

    @PostMapping(value = "/create")
     @ApiOperation(value = "后台用户角色表 创建")
    public void create(@RequestBody Role params) {
        iRoleService.save(params);
    }

    @PostMapping(value = "/delete/{id}")
     @ApiOperation(value = "后台用户角色表 删除")
    public void delete(@PathVariable("id") String id) {
        iRoleService.removeById(id);
    }


      @PostMapping(value = "/enable/{id}/{enableYn}")
         @ApiOperation(value = "用户 是否启用（0禁用 1启用）")
           public void enable(@PathVariable("id") String id,@PathVariable("enableYn") Boolean enableYn) {
               Role entity = new Role();
               entity.setEnableYn(enableYn);
               iRoleService.updateById(entity);
           }



            @PostMapping(value = "/delFlag/{id}/{delFlag}")
        @ApiOperation(value = "用户 删除标志（0正常 1停用）")
           public void delFlag(@PathVariable("id") String id,@PathVariable("delFlag") Boolean delFlag) {
               Role entity = new Role();
               entity.setDelFlag(delFlag);
               iRoleService.updateById(entity);
           }


    @PostMapping(value = "/update")
     @ApiOperation(value = "后台用户角色表 更新")
    public void update(@RequestBody Role params) {
        iRoleService.updateById(params);
    }















}
